var Demo = {
	LOGIN_STATUS:{
		SUCCESS:0,//成功
		TIMEOUT:1,//超时
		INVALID_USERNAME:2,//用户名错误
		INVALID_PASSWORD:3,//密码错误
		INVALID_APPID:5,
		OTHER:99//其他错误
	},
	LOGOUT_STATUS:{
		SUCCESS:0,//成功
		FAILED:1,//失败
	},
	CALL_OUT_STATUS:{
		TIMEOUT:0,//外呼超时
		CALLER_REFUSE:1,//坐席拒接
		CALLER_NO_ANSWER:2,//坐席无应答
		CALLER_INEXISTENCE:3,//坐席不存在
		CALLER_CALL_FAILED:4,//坐席呼叫失败
		CALLER_RINGING:5,//坐席振铃
		CALLER_ANSWER:6,//坐席接听
		CALLED_REFUSE:7,//被叫拒绝
		CALLED_NO_ANSWER:8,//被叫无应答
		CALLED_INEXISTENCE:9,//被叫不存在
		CALLED_CALL_FAILED:10,//呼叫被叫失败
		CALLED_RINGING:11,//被叫振铃
		CALLED_ANSWER:12,//被叫接听
		CALLER_HANG_UP:13,//坐席挂机
		CALLED_HANG_UP:14,//被叫挂机
		M_PERMISSION_REQUESTED:15,//申请获取音频
		M_PERMISSION_FAILED:16,//获取音频失败
		M_PERMISSION_OK:17,//获取音频成功
		UN_KNOWN:99//未知
	},
	CALL_TYPES:{
		CALL_INCOMING:"incoming",
		CALL_OUT:"callOut"
	},
	SendCallTypes:{
		free:0,
		directly:1,
		intelligence:2
	},
	init:function(){
  	this.isIncoming = false;//是否为来电
		this.callStatus = "none";
		this.checkInServer = this.checkInServer || "";
  	this.initEvents();
	},
	sendCall:function(type){
		var sendNo = this.callTargetInput.val();
		sendNo = $.trim(sendNo);
		if(sendNo.length===0){
			alert("请填写被叫方号码");
			return;
		}
		type = this.SendCallTypes[type];
		var ret = UCSConnect.MakeNewCall(type,sendNo);
		if(ret < 0){
			alert("呼叫失敗");
			return;
		}
		this.callType = this.CALL_TYPES.CALL_OUT;//呼出
		this.setTipMsg("正在呼叫...");
		this.callStatus = "send_out";
	},
	initEvents:function(){},
	doLogin:function(userName, password, appId){
		UCSConnect.setAppId(appId);
		var ret = UCSConnect.login(userName,password);
		if(ret === false){
			alert("登录失败，请查看控制台信息");
		} else {
		  isValid = true;
		}
	},
	setTipMsg:function(msg){
		$.bootstrapGrowl(msg);
	},
	sendCrossDomainData:function(){
		var that = this;
		var xhr = new XMLHttpRequest();
	    xhr.onload = function(){
	    	that.checkInRet.text(xhr.responseText);
	    };
	    xhr.onerror = function(){
	    	that.setTipMsg("签入服务器连接异常");
	    };
	    xhr.open('GET', this.checkInServer, true);
	    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    xhr.send(null);
	}
};

function destorySource(){
	try{
		UCSConnect.logout();
		UCSConnect.CallGiveUp();
	}catch(e){

	}
};